package login.web.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author Administrator
 * @Date 2020/6/9 15:48
 * JDBC工具类
 **/
public class JDBCUtils {
    private static DataSource ds;
    static {
        /*1、读取配置文件
        * 2、初始化ds*/
        Properties pro = new Properties();
        /*传入参数：通过类加载将文件转成流对象*/
        try {
            pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
            ds= DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static DataSource getDataSoutce(){
        return ds;
    }
    public static Connection getConnection() throws SQLException{
        return ds.getConnection();
    }
}
